<?php if(!defined('IN_FIRADIO')) {header('HTTP/1.1 403 Forbidden');exit('<h1>Access Denied</h1>');}?>
<?php $GLOBALS['script'][] = function() {?><script>
vue.methods.postapi = function () {
    const that = this;
    that.init();
    that.ApiPost('/panel/ip/proxyurl_list.php', that.form).then(function (data) {
        vue.data.apidata = data.data;
    }, function (data) {
        //console.log('reject:', data);
    });
};
vue.methods.postapi_add = function () {
    const that = this;
    that.ApiPost('/panel/ip/proxyurl_add.php', that.form_add).then(function (data) {
        vue.methods.postapi();
    }, function (data) {
        //console.log('reject:', data);
    });
};
vue.methods.postapi_save = function (row) {
    const that = this;
    that.ApiPost('/panel/ip/proxyurl_save.php', row).then(function (data) {
        vue.methods.postapi();
    }, function (data) {
        //console.log('reject:', data);
    });
};
vue.methods.postapi_del = function () {
    const that = this;
    const del_ids = [];
    for (var key in that.apidata.rows) {
        const row = that.apidata.rows[key];
        if (row.del) del_ids.push(row.id);
    }
    if (del_ids.length <= 0) {
        alert('请先选择要删除的记录');
        return;
    }
    if (!confirm("确定要删除这" + del_ids.length + "条记录吗？")) return;
    that.ApiPost('/panel/ip/proxyurl_del.php', {'del_ids':del_ids}).then(function (data) {
        vue.methods.postapi();
    }, function (data) {
        //console.log('reject:', data);
    });
};
vue.methods.init = function () {
    vue.data.disabled = false;
    vue.data.apidata = {};
    vue.data.apidata.rows = [];
    vue.data.form_add = {};
    vue.data.form_add.url = '';
    vue.data.form_add.timeout = 1;
};
vue.methods.init();
vue.mounted = function () {
    vue.methods.postapi();
};
</script><?php }?>

<!-- Custom Tabs -->
<form v-on:submit="postapi" onsubmit="return false" :disabled="disabled">
<div class="nav-tabs-custom">

    <table class="table table-bordered table-striped dataTable">
        <tr align="center">
            <td>ID</td>
            <td>来源名称</td>
            <td style="min-width:400px;">获取URL</td>
            <td>间隔(秒)</td>
            <td>操作</td>
            <td>状态</td>
            <td>10秒</td>
            <td>1分</td>
            <td>5分</td>
            <td>10分</td>
            <td>60分</td>
            <td>删除</td>
        </tr>
        <tr v-for="row in apidata.rows" align="center">
            <td>{{row.id}}</td>
            <td><input style="width:100%" v-on:change="postapi_save(row)" v-model="row.title" /></td>
            <td><input style="width:100%" v-on:change="postapi_save(row)" v-model="row.url" :disabled="!!row.enable" /></td>
            <td><input style="width:100%" v-on:change="postapi_save(row)" v-model="row.timeout" :disabled="!!row.enable" /></td>
            <td><label><input type="checkbox" v-on:change="postapi_save(row)" v-model="row.enable" />启用</label></td>
            <td>
                <span v-if="!!row.enable">
                    <span v-if="((+new Date()/1000)-row.fetched)<10">
                        <span style="color:#00cc00;font-family:宋体;">●</span>
                    </span>
                    <span v-else>
                        <span style="color:red;font-family:宋体;">●</span>
                    </span>
                </span>
                <span v-else>-</span>
            </td>
            <td>{{row.count10}}</td>
            <td>{{row.count60}}</td>
            <td>{{row.count300}}</td>
            <td>{{row.count600}}</td>
            <td>{{row.count3600}}</td>
            <td><label><input type="checkbox" v-model="row.del" />删除</label></td>
        </tr>
        <tr align="center">
            <td>新增</td>
            <td>-</td>
            <td><input style="width:100%" v-on:change="postapi_add" v-model="form_add.url" required /></td>
            <td><input style="width:100%" v-on:change="postapi_add" v-model="form_add.timeout" /></td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td><button class="btn btn-default btn-xs" type="button" v-on:click="postapi_del()">删除</button></td>
        </tr>
    </table>
</div>
</form>
